package com.storm.demo;

import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.BasicOutputCollector;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseBasicBolt;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;

import java.time.LocalDate;
import java.util.Map;

/**
 * =================================
 * <p>
 * Created by cjj on 2018/10/23.
 * <p>
 * 描述: 添加后缀 并写入到数据库
 */

public class SuffixBlot extends BaseBasicBolt {

    /**
     * bolt组件初始化只会调用一次
     *
     * @param map
     * @param topologyContext
     */
    @Override
    public void prepare(Map map, TopologyContext topologyContext) {
    }

    //业务处理逻辑
    @Override
    public void execute(Tuple tuple, BasicOutputCollector collector) {
        //先获取上一个数组传递过来的数据，数据在tuple里面
        String string = tuple.getString(0);

        //逻辑，添加后缀
        String s = string + LocalDate.now().toString();

        collector.emit(new Values(s));
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer declarer) {

    }
}

